//Relatorio.java
// Classe de controle de relatorio
package controle;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

/**
 * @author Diego Heusser
 * @author Eder Schramm
 */
public class Relatorio {

    public void relatorioMotorista() throws Exception {
        dao.DAOFactory factory = dao.DAOFactory.getDAOFactory();
        List<modelo.Motorista> lista = factory.getMotoristaDAO().listar();

        String relatorio = "relatorio\\motorista.jasper";
        Map<String, Object> parametrosRelatorio = new HashMap<>();

        parametrosRelatorio.put("LISTA", lista);

        JasperPrint print = JasperFillManager.fillReport(relatorio, parametrosRelatorio, new JRBeanCollectionDataSource(lista));

        JasperViewer viewer = new JasperViewer(print, false);
        viewer.setVisible(true);
        viewer.toFront();
    }

    public void relatorioAutomovel() throws Exception {
        dao.DAOFactory factory = dao.DAOFactory.getDAOFactory();
        List<modelo.Automovel> lista = factory.getAutomovelDAO().listar();

        String relatorio = "relatorio\\automovel.jasper";
        Map<String, Object> parametrosRelatorio = new HashMap<>();

        parametrosRelatorio.put("LISTA", lista);

        JasperPrint print = JasperFillManager.fillReport(relatorio, parametrosRelatorio, new JRBeanCollectionDataSource(lista));

        JasperViewer viewer = new JasperViewer(print, false);
        viewer.setVisible(true);
        viewer.toFront();
    }
}
